package com.cyandpos.pad.activity;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.RemoteException;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.cyandpos.pad.R;
import com.cyandpos.pad.sale.view.SelfNumKeyView;
import com.cyandpos.pad.utils.CommonUtils;
import com.cyandpos.pad.utils.ToastUtils;

import butterknife.BindView;

public class OpenCashboxActivity extends BaseActivity implements View.OnClickListener {
    @BindView(R.id.tv_dialog_title_name)
    TextView mTvTitleName;
    @BindView(R.id.ed_cashbox_pw)
    EditText mEtTicketno;
    @BindView(R.id.ed_cashbox_keyboard)
    SelfNumKeyView sf_containt;
    @BindView(R.id.btn_opencashbox)
    Button btnopencashbox;
    @Override
    protected void initData() {
        sf_containt.setEnterReceptor(mEtTicketno);
        sf_containt.setIsCanInputPoint(true);
        sf_containt.setOnCallBack(new SelfNumKeyView.SelfNumCallBack() {
            @Override
            public void keyBoardSure(String num,String hint) {

                SharedPreferences sp = getSharedPreferences("USER", Context.MODE_PRIVATE);
                String pwd = sp.getString("pwd", null);
                if ((pwd.equals(num))) {
                    ToastUtils.show("密码正确,开启钱箱");
                    finish();

                } else {
                    ToastUtils.show("密码不正确，请重新输入！");
                }
            }
        });

        mTvTitleName.setOnClickListener(this);
        btnopencashbox.setOnClickListener(this);
        CommonUtils.setNoSoftware(mEtTicketno, OpenCashboxActivity.this, true);

    }

    @Override
    protected void onResume() {
        super.onResume();
        mTvTitleName.setText("打开钱箱");
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_open_cashbox;
    }

    @Override
    public void onClick(View v) {
          switch (v.getId()){
              case R.id.tv_dialog_title_name:
                  finish();
                  break;
              case R.id.btn_opencashbox:

                  SharedPreferences sp = getSharedPreferences("USER", Context.MODE_PRIVATE);
                  String pwd = sp.getString("pwd", null);
                  if ((pwd.equals(mEtTicketno.getText().toString()))) {
                      ToastUtils.show("密码正确,开启钱箱");
                      finish();

                  } else {
                      ToastUtils.show("密码不正确，请重新输入！");
                  }

                  break;
                  default:
                      break;
          }
    }
}
